<template>
    <div style="height: 95%;width: 100%;display:flex;justify-content:center;padding-top: 20px">
        <!--弹框DIV 设置弹框的大小的地方-->
        <div style="background: #fff;width: 700px;height: 600px;box-shadow: #D3DCE6 0px 0px 20px;">
            <div style="height:520px;border: #1C84C6;margin-top: 25px" class="scrollbar">
                <div style="height: 30px;">
                    <!--标题-->
                    <span style="font-size: 18px;margin-left: 25px;">
                        出差申请
                    </span>
                    <!--返回列表-->
                    <router-link style="margin-left: 530px;" :to="{path:'/chucha'}">
                        <span>
                            <i slot="suffix" style="font-size: 30px;color: #D3DCE6" class="el-icon-close"></i>
                        </span>
                    </router-link>
                </div>
                <!--height:91%;表单在弹框显示多长-->
                <el-scrollbar style="height:91%;padding-top: 20px;">
                    <div class="shugan"></div>
                    <span style="margin-left: 10px;font-size: 14px;">基本信息</span>
                    <br/>
                    <br/>
                    <!--表单-->
                    <el-form style="margin-top:5px;margin-left: 40px;" size="mini" :model="addlchucha" :rules="rules"  >
                        <el-row>
                            <el-col :span="11">
                                <el-form-item style="width:250px;"  prop="ccZhuti">
                                    <label slot="label" style="font-size: 13px">主题：</label><br/>
                                    <el-input v-model="addlchucha.ccZhuti"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item style="width:250px;" prop="ccMdd">
                                    <label slot="label" style="font-size: 13px">目的地：</label><br/>
                                    <el-input v-model="addlchucha.ccMdd"></el-input>
                                </el-form-item>
                            </el-col>

                        </el-row>


                        <el-row>
                            <el-col :span="11">
                                <el-form-item style="width:250px;" prop="ccKstime">
                                    <label slot="label" style="font-size: 13px">开始时间：</label><br/>
                                    <el-date-picker
                                            v-model="addlchucha.ccKstime"
                                            type="date"
                                            placeholder="选择日期"
                                            style="width: 250px">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>

                            <el-col :span="8">
                                <el-form-item style="width:250px" prop="ccJstime">
                                    <label slot="label" style="font-size: 13px">结束时间：</label><br/>
                                    <el-date-picker
                                            v-model="addlchucha.ccJstime"
                                            type="date"
                                            placeholder="选择日期"
                                            style="width: 250px">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="11">
                                <el-form-item style="width:250px;">
                                    <label slot="label" style="font-size: 13px">交通工具：</label><br/>
                                    <el-select v-model="addlchucha.ccJtgj" placeholder="全部数据" style="width: 250px" >
                                        <el-option
                                                v-for="item in options"
                                                :key="item.value"
                                                :label="item.label"
                                                :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item style="width:250px;" prop="clientId">
                                    <label slot="label" style="font-size: 13px">客户：</label><br/>
                                    <!--客户名称-->
                                    <el-popover
                                            style="width: 700px; height: 450px;"
                                            placement="right"
                                            trigger="click"
                                            v-model="kehu">
                                        <span style="font-size: 16px;">关联客户模块</span>
                                        <br/>
                                        <el-input @keyup.enter.native="initData" v-model="kehuinput" style="width: 210px; margin-left: 230px; margin-bottom: 10px;">
                                            <i slot="suffix" class="el-input__icon el-icon-search" @click="initData"></i>
                                        </el-input>
                                        <el-table
                                                highlight-current-row
                                                border
                                                ref="kehulist"
                                                :data="kehulist">
                                            <el-table-column type="selection" width="50" align="center" property="clientId"></el-table-column>
                                            <el-table-column width="150" property="clientName" label="客户名称"></el-table-column>
                                            <el-table-column width="100" property="clientRank" label="级别"></el-table-column>
                                            <el-table-column width="150" property="clientMobile" label="手机号码"></el-table-column>
                                            <el-table-column width="200" property="clientSite" label="地址"></el-table-column>
                                        </el-table>
                                        <el-pagination
                                                style="margin-left: 350px;"
                                                layout="prev, pager, next"
                                                :page-size="pageSize"
                                                :current-page.sync="currPage"
                                                :total="totalSize">
                                        </el-pagination>
                                        <div style="text-align: center;width: 100%" class="dialog-footer">
                                            <el-button type="primary" @click="xzkehu">保 存</el-button>
                                            <el-button type="primary" @click="kehu = false">取 消</el-button>
                                        </div>
                                        <el-input v-model="clientId.clientName" placeholder="+添加" slot="reference" :readonly='true' style="width: 250px;"></el-input>
                                    </el-popover>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="11">
                                <el-form-item style="width:250px;">
                                    <label slot="label" style="font-size: 13px">申请人：</label><br/>
                                    <el-input :disabled="true" v-model="addlchucha.empId.empName" ></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item style="width:250px">
                                    <label slot="label" style="font-size: 13px">状态：</label><br/>
                                    <el-input :disabled="true" v-model="addlchucha.ccZt"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
<!--                            <el-col :span="11">-->
<!--                                <el-form-item style="width:250px;" >-->
<!--                                    <label slot="label" style="font-size: 13px">借款：</label><br/>-->
<!--                                    <el-input ></el-input>-->
<!--                                </el-form-item>-->
<!--                            </el-col>-->
                            <el-col :span="8">
                                <el-form-item style="width:250px">
                                    <label slot="label" style="font-size: 13px">备注：</label><br/>
                                    <el-input v-model="addlchucha.ccBeizhu"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>



                    </el-form>


                </el-scrollbar>
                <!--确定按钮 设置了固定定位-->
                <div style="text-align: center;width: 80%;position: absolute;top:655px;left:230px;" class="dialog-footer">
                    <!--返回列表-->
                    <router-link :to="{path:'/chucha'}">
                        <el-button >取 消</el-button>
                    </router-link>
                    &nbsp;&nbsp;
                    <el-button type="primary" @click="xzlchucha()" >确 定</el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {formatTimeToStr} from '../router//format.js'
    export default {
        name: "Lchuchasqtk",
        data() {
            return {
                options:[{
                    value: '飞机',
                    label: '飞机'
                }, {
                    value: '坦克',
                    label: '坦克'
                },{
                    value: '汽车',
                    label: '汽车'
                },{
                    value: '其他',
                    label: '其他'
                }],
                tsr:'',
                clientId:{
                    clientId:'',
                    clientName:'',
                },
                addlchucha:{
                    ccId:0,//出差ID
                    empId:{
                        empId:'1',
                        empName:'aa'
                    },//员工
                    ccZhuti: '',//出差主题
                    ccMdd: '',//出差目的地
                    ccDdykehu:'',//对应客户
                    ccKstime: '',//出差开始时间
                    ccJstime: '',//出差结束时间
                    ccZt: '未审核',//审批状态
                    ccLx: '',//出差类型
                    ccJtgj: '',//出差交通工具
                    ccBeizhu: '',//出差备注
                    ccZtcx:'1',//记录状态查询
                },
                rules: {
                    ccZhuti: [
                        {required: true, message: '请输入出差主题', trigger: 'blur'}
                    ],
                    ccMdd: [
                        {required: true, message: '请输入出差目的地', trigger: 'blur'}
                    ],
                    ccKstime: [
                        {required: true, message: '请选择时间', trigger: 'blur'}
                    ],
                    ccJstime: [
                        {required: true, message: '请选择时间', trigger: 'blur'}
                    ],
                },
                kehu:false,//客户弹出框
                kehuinput:'',//客户弹框搜索框
                hueikuanlist:[],//回款表格信息
                kehulist:[],//客户表格信息
                //表单
                pageSize:5,//客户分页页大小
                currPage:1,//客户当前页码，默认为1
                totalSize:0,//客户总记录数
                hxkkehu:0,//回款页面绑定客户查询
                xg:0//判断是新增还是修改
            };
        },methods:{
            //选择客户确定按钮
            xzkehu() {
                this.$refs.kehulist.selection.forEach((pro)=>{
                    this.clientId=pro;

                });
                this.addlchucha.ccDdykehu=this.clientId.clientName
                this.kehu=false;
                this.kehuinput='';
                // window.console.log(this.addlchucha.clientId);
            },

            //客户查询方法
            initData(){
                this.$axios.post("http://localhost:8088/client-list",this.qs.stringify(
                    {search:this.kehuinput, page:this.currPage, size:this.pageSize,}))
                    .then(v=>{
                        this.kehulist = v.data.rows;
                        this.totalSize = v.data.total;
                    })
                    .catch()
            },
            //新增出差记录
            xzlchucha(){
                if(this.xg==0){
                    this.$confirm('是否确定新增?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.$axios.post("http://localhost:8088/vue/addlchucha",this.addlchucha)
                            .then(()=>{
                                this.$message({
                                    showClose: true,
                                    type: 'success',
                                    message: '新增成功!',
                                });
                                this.$router.push({
                                    path:'/chucha'
                                });
                            }).catch(()=>{
                                this.$message({
                                    showClose: true,
                                    message: '新增失败',
                                    type: 'error'
                                });
                            }
                        )
                    }).catch(() => {
                        this.$message({
                            showClose: true,
                            type: 'info',
                            message: '已取消新增'
                        });
                    });
                }else {
                    this.$confirm('是否确定修改?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.$axios.post("http://localhost:8088/vue/addlchucha",this.addlchucha)
                            .then(()=>{
                                this.$message({
                                    showClose: true,
                                    type: 'success',
                                    message: '修改成功!',
                                });
                                this.$router.push({
                                    path:'/chucha'
                                });
                            }).catch(()=>{
                                this.$message({
                                    showClose: true,
                                    message: '修改失败',
                                    type: 'error'
                                });
                            }
                        )
                    }).catch(() => {
                        this.$message({
                            showClose: true,
                            type: 'info',
                            message: '已取消修改'
                        });
                    });
                }

            },

        },created:function() {
            if(this.$route.query.key!=null){
                this.addlchucha=this.$route.query.key;
                this.clientId.clientName=this.$route.query.key.ccDdykehu
                this.xg = 1;
            }
            //客户查询
            this.initData();
        },
        filters: {
            formatDate: function (time) {
                if (time != null && time != "") {
                    var date = new Date(time);
                    return formatTimeToStr(date, "yyyy-MM-dd");
                } else {
                    return "";
                }
            }
        }
    }
</script>

<style scoped>
    .shugan{
        border-left-color: rgb(70, 205, 207);
        border-left-width: 1.8px;
        height: 10px;
        border-left-style: solid;
        display: inline;
        font-size: 13px;
        margin-left: 25px;
    }

    /deep/ .el-scrollbar__wrap {
        overflow: scroll;
        width: 120%;
        height: 100%;
    }
</style>